package com.specialized.orders.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.specialized.common.core.domain.Result;
import com.specialized.common.core.utils.poi.ExcelUtil;
import com.specialized.orders.common.domain.Distance;
import com.specialized.orders.common.domain.RealTime;
import com.specialized.orders.service.IRealTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.specialized.common.security.annotation.RequiresPermissions;
import com.specialized.common.core.web.controller.BaseController;

/**
 * 实时订单Controller
 *
 * @author djh
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/RealTime")
public class RealTimeController extends BaseController {
    @Autowired
    private IRealTimeService realTimeService;


/**
 * 查询实时订单列表
 */
//@RequiresPermissions("orders:RealTime:list")
    @GetMapping("/list")
    public Result list(RealTime realTime) {
        startPage();
        List<RealTime> list = realTimeService.selectRealTimeList(realTime);
        return getDataTable(list);
    }

    /**
     * 导出实时订单列表
     */
    @RequiresPermissions("orders:RealTime:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, RealTime realTime) {
        List<RealTime> list = realTimeService.selectRealTimeList(realTime);
        ExcelUtil<RealTime> util = new ExcelUtil<RealTime>(RealTime. class);
        util.exportExcel(response, list, "实时订单数据");
    }

    /**
     * 获取实时订单详细信息
     */
    @RequiresPermissions("orders:RealTime:query")
    @GetMapping(value = "/{realtimeId}")
    public Result getInfo(@PathVariable("realtimeId") Long realtimeId) {
        return success(realTimeService.selectRealTimeByRealtimeId(realtimeId));
    }

    /**
     * 新增实时订单
     */
    @RequiresPermissions("orders:RealTime:add")
    @PostMapping
    public Result add(@RequestBody RealTime realTime) {
        return toAjax(realTimeService.insertRealTime(realTime));
    }

    /**
     * 修改实时订单
     */
    @RequiresPermissions("orders:RealTime:edit")
    @PutMapping
    public Result edit(@RequestBody RealTime realTime) {
        return toAjax(realTimeService.updateRealTime(realTime));
    }

    /**
     * 删除实时订单
     */
    @RequiresPermissions("orders:RealTime:remove")
    @DeleteMapping("/{realtimeIds}")
    public Result remove(@PathVariable Long[] realtimeIds) {
        return toAjax(realTimeService.deleteRealTimeByRealtimeIds(realtimeIds));
    }


    /**
     * 实时订单
     */
    @PostMapping("/addRealTimeOrders")
    public Result addRealTimeOrders(@RequestBody RealTime realTime){
        Result result = realTimeService.addRealTimeOrders(realTime);
        return result;
    }


    /**
     * 根据地址信息获取经纬度
     */
    @GetMapping("/addAddrLongitudeLatitude/{addr}")
    public Result addAddrLongitudeLatitude(@PathVariable String addr){
        Result result = realTimeService.addAddrLongitudeLatitude(addr);
        return result;
    }


    /**
     * 根据经纬度计算两地点之间距离
     */
    @GetMapping("/computeDistance/{origin}/{destination}")
    public Result computeDistance(@PathVariable String origin,@PathVariable String destination){
        Distance driver = realTimeService.computeDistance(origin, destination);
        return Result.success(driver);
    }


//    /**
//     * 发起订单
//     */
//    @PostMapping("/addRealTime")
//    public Result addRealTime(@RequestBody RealTime realTime){
//        realTimeService.addRealTime(realTime);
//        return Result.success();
//    }


    /**
     * 计价规则
     */
    @PostMapping("/computeMoneyrule")
    public Result computeMoneyrule(@RequestBody RealTime realTime){
        realTimeService.computeMoneyrule(realTime);
        return Result.success();
    }


    /**
     * 根据订单号查询
     */
    @PostMapping("/selectRealTimeOrderCard")
    public Result selectRealTimeOrderCard(@RequestBody String orderCard) {
        RealTime realTimeOrderCard = realTimeService.selectRealTimeOrderCard(orderCard);
        return Result.success(realTimeOrderCard);
    }





}
